package com.aiyige.page.publish.coursedescription.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by zhuyakun on 2018/3/20.
 */

public class CourseCover implements Parcelable {
    public static final int TYPE_NORMAL = 1;
    public static final int TYPE_ADD = 2;
    public static final int MEDIA_TYPE_PHOTO = 1;
    public static final int MEDIA_TYPE_VIDEO = 2;

    private String videoUrl;
    private String imageUrl;
    private boolean needUpload;
    private long duration;
    private long size;
    boolean defaultCover;
    int type;
    int mediaType;
    int uploadFileId;

    public CourseCover() {
    }

    private CourseCover(Builder builder) {
        setVideoUrl(builder.videoUrl);
        setImageUrl(builder.imageUrl);
        setNeedUpload(builder.needUpload);
        setDuration(builder.duration);
        setSize(builder.size);
        setDefaultCover(builder.defaultCover);
        setType(builder.type);
        setMediaType(builder.mediaType);
        setUploadFileId(builder.uploadFileId);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getVideoUrl() {
        return videoUrl;
    }

    public void setVideoUrl(String videoUrl) {
        this.videoUrl = videoUrl;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public boolean isNeedUpload() {
        return needUpload;
    }

    public void setNeedUpload(boolean needUpload) {
        this.needUpload = needUpload;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public boolean isDefaultCover() {
        return defaultCover;
    }

    public void setDefaultCover(boolean defaultCover) {
        this.defaultCover = defaultCover;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getMediaType() {
        return mediaType;
    }

    public void setMediaType(int mediaType) {
        this.mediaType = mediaType;
    }

    public int getUploadFileId() {
        return uploadFileId;
    }

    public void setUploadFileId(int uploadFileId) {
        this.uploadFileId = uploadFileId;
    }

    public static final class Builder {
        private String videoUrl;
        private String imageUrl;
        private boolean needUpload;
        private long duration;
        private long size;
        private boolean defaultCover;
        private int type;
        private int mediaType;
        private int uploadFileId;

        private Builder() {
            videoUrl = "";
            imageUrl = "";
            needUpload = true;
            duration = 0;
            size = 0;
            defaultCover = false;
            type = TYPE_NORMAL;
            mediaType = MEDIA_TYPE_PHOTO;
            uploadFileId = 0;
        }

        public Builder videoUrl(String videoUrl) {
            this.videoUrl = videoUrl;
            return this;
        }

        public Builder imageUrl(String imageUrl) {
            this.imageUrl = imageUrl;
            return this;
        }

        public Builder needUpload(boolean needUpload) {
            this.needUpload = needUpload;
            return this;
        }

        public Builder duration(long duration) {
            this.duration = duration;
            return this;
        }

        public Builder size(long size) {
            this.size = size;
            return this;
        }

        public Builder defaultCover(boolean defaultCover) {
            this.defaultCover = defaultCover;
            return this;
        }

        public Builder type(int type) {
            this.type = type;
            return this;
        }

        public Builder mediaType(int mediaType) {
            this.mediaType = mediaType;
            return this;
        }

        public Builder uploadFileId(int uploadFileId) {
            this.uploadFileId = uploadFileId;
            return this;
        }

        public CourseCover build() {
            return new CourseCover(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.videoUrl);
        dest.writeString(this.imageUrl);
        dest.writeByte(this.needUpload ? (byte) 1 : (byte) 0);
        dest.writeLong(this.duration);
        dest.writeLong(this.size);
        dest.writeByte(this.defaultCover ? (byte) 1 : (byte) 0);
        dest.writeInt(this.type);
        dest.writeInt(this.mediaType);
        dest.writeInt(this.uploadFileId);
    }

    protected CourseCover(Parcel in) {
        this.videoUrl = in.readString();
        this.imageUrl = in.readString();
        this.needUpload = in.readByte() != 0;
        this.duration = in.readLong();
        this.size = in.readLong();
        this.defaultCover = in.readByte() != 0;
        this.type = in.readInt();
        this.mediaType = in.readInt();
        this.uploadFileId = in.readInt();
    }

    public static final Parcelable.Creator<CourseCover> CREATOR = new Parcelable.Creator<CourseCover>() {
        @Override
        public CourseCover createFromParcel(Parcel source) {
            return new CourseCover(source);
        }

        @Override
        public CourseCover[] newArray(int size) {
            return new CourseCover[size];
        }
    };
}
